/**
 * @param {character[][]} board
 * @param {string} word
 * @return {boolean}
 * @description 超时
 */
var exist = function (board, word) {
    let row = board.length
    let col = board[0].length
    let flag = false
    for (let i = 0; i < row; i++) {
        for (let j = 0; j < col; j++) {
            let str = ""
            dfs(i, j, str, board)
        }
    }
    return flag
    function dfs(x, y, str, board) {
        // 如果长度相等
        if (str === word) {
            flag = true
            return
        }
        if (str.length > word.length) {
            return
        }
        // 如果在范围内
        if (x < 0 || x >= row || y < 0 || y >= col || board[x][y] === 0) {
            return
        } else {
            let ele = board[x][y]
            str += ele
            board[x][y] = 0
            dfs(x + 1, y, str, board)
            dfs(x - 1, y, str, board)
            dfs(x, y + 1, str, board)
            dfs(x, y - 1, str, board)
            board[x][y] = ele
        }
    }
};